package com.qianxiwitpatients.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianxi.wit.pojo.TbDiagnosticLogout;
import com.qianxi.wit.pojo.TbSufferer;
import com.qianxi.wit.result.R;
import com.qianxiwitpatients.service.AlipayService;
import com.qianxiwitpatients.service.TbSuffererService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/patient")
@CrossOrigin
public class TbSuffererController {
    @Autowired
    private TbSuffererService tbSuffererService;
    @Autowired
    private AlipayService alipayService;

    @GetMapping("/findAllpatient/{page}/{pageSize}")
    private R findByPage(@PathVariable("page") int page,
                         @PathVariable("pageSize") int pageSize){
        try {
            Page<TbSufferer> list =  tbSuffererService.findAll(page,pageSize);
            return R.ok().data("total",list.getTotal()).data("list",list.getRecords());
        }catch (Exception e){
            return R.error();
        }
    }

    @GetMapping("/findAllPatientId")
    private R findAll(@RequestParam(value = "page",defaultValue = "1") int page,
                      @RequestParam(value = "pageSize",defaultValue = "3") int pageSize,
                      @RequestParam(value = "id",defaultValue = "0") long id){
        try {
            Page<TbDiagnosticLogout> list =  tbSuffererService.findSufferer(page,pageSize,id);
            return R.ok().data("total",list.getTotal()).data("list",list.getRecords());
        }catch (Exception e){
            return R.error();
        }
    }

    //诊断记录详情
    @GetMapping("/findbyid/{id}")
    public R findbyid(@PathVariable("id") int id){
        try {
            return R.ok().data("suffer",tbSuffererService.findbyid(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }


    @GetMapping("/alipay")
    public void alipay(){
        alipayService.alipay();
    }

}
